import uuid

from sqlalchemy import DateTime, Boolean, String, func, Column
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.sql import expression
from datetime import datetime

from utils import snowflake
from utils.snowflake import snowflake
from server.etc.database import Base



class BaseModel(Base):
    __abstract__ = True
    id: Mapped[str] = mapped_column(
        String(20),
        primary_key=True,
        default=lambda: str(snowflake.generate_id())
    )
    is_deleted: Mapped[bool] = mapped_column(
        Boolean,
        default=False,
        nullable=False,
        server_default=expression.false()
    )
    created_at: Mapped[datetime] = mapped_column(
        DateTime,
        server_default=func.now(),
        default=datetime.now()
    )
    updated_at: Mapped[datetime] = mapped_column(
        DateTime,
        server_default=func.now(),
        onupdate=func.now(),
        default=datetime.now()
    )

